<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><title>Running long JavaScript processes in a web browser (optimized version)</title>

  
    
    <style>

body {
  padding:0;
  margin:1em;
}

#progressbar {
  position:relative;
  width:300px; height:20px;
  border:1px solid black;
  overflow:hidden;
}

#progressbar div {
  background:#316AC5;
  width:0; height:100%;
}
    </style></head><body>
    <p>Sorting, please wait...</p>
    <div id="progressbar"><div style="width: 100%;"></div></div>
    <div id="out"></div>

    <script>
function test() {
  for(var i=0; i < 1000; i++) {
    if (i == 2) return;
    alert(i); 
  }
}
test();
    </script>
  
</body></html>